package com.jzg.jcptadmin.presenter;

import com.jzg.jcptadmin.base.BasePresenter;
import com.jzg.jcptadmin.data.DataManager;
import com.jzg.jcptadmin.data.vo.CheckVinBean;
import com.jzg.jcptadmin.viewinterface.CheckVinAccidentInterface;

import java.util.Map;

import rx.Observer;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by liugl on 2017/2/21.
 */

public class CheckVinPrsenter extends BasePresenter<CheckVinAccidentInterface>{

    private DataManager dataManager;
    private Subscription mSubscription;
    private CheckVinAccidentInterface mView;

    public CheckVinPrsenter(DataManager instance){
        super();
        this.dataManager = instance;
    }
    //@Override
    public void attachView(CheckVinAccidentInterface mvpView) {
        super.attachView(mvpView);
        mView = mvpView;
    }

    @Override
    public void detachView() {
        super.detachView();
        if (mSubscription != null) mSubscription.unsubscribe();
    }

    public void checkvin(){

        Map<String, String> params = mView.getcheckVinParams();
        if (!checkSubmitInfo(params)) return;
        mSubscription = dataManager.checkVinAccidentOperation(params).observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<CheckVinBean>() {
                    @Override
                    public void onCompleted() {
//                        view.dismissDialog();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.checkVinFail("");
                    }

                    @Override
                    public void onNext(CheckVinBean successData) {
                        mView.checkVinSucc(successData);
                    }
                });

    }

}
